//
//  XGRecommendTableViewCell.m
//  BSBuDeJie
//
//  Created by monkey on 2018/12/11.
//  Copyright © 2018 itcast. All rights reserved.
//

#import <Masonry/Masonry.h>

#import "UIImageView+Extension.h"

#import "XGRecommendTagTableViewCell.h"

#import "XGNewsRecommendTagModel.h"

@interface XGRecommendTagTableViewCell ()

/// 头像
@property (nonatomic,strong) UIImageView *iconImageView;
/// 名称
@property (nonatomic,strong) UILabel *nameLabel;
/// 订阅数
@property (nonatomic,strong) UILabel *subscribeNumberLabel;
/// 订阅按钮
@property (nonatomic,strong) UIButton *subscribeButton;

@end

@implementation XGRecommendTagTableViewCell

#pragma mark - 解析模型

- (void)setRecommendTagModel:(XGNewsRecommendTagModel *)recommendTagModel
{
    _recommendTagModel = recommendTagModel;
    [self.iconImageView xg_setImageWithURLString:recommendTagModel.imageList placeHolder:kPlaceHolderImage];
    self.nameLabel.text = recommendTagModel.themeName;
    self.subscribeNumberLabel.text = [[NSString stringFromNumberToString:recommendTagModel.subNumber] stringByAppendingString:@"人关注"];
}

#pragma mark - 构造方法

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI
{
    // 添加子控件
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.subscribeNumberLabel];
    [self.contentView addSubview:self.subscribeButton];
    
    //  设置自动布局
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(kMargin);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(kUserIconWidth,kUserIconWidth));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView);
        make.left.equalTo(self.iconImageView.mas_right).offset(kMargin);
    }];
    
    [self.subscribeNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(kMargin);
        make.bottom.equalTo(self.iconImageView.mas_bottom);
    }];
    
    [self.subscribeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-kMargin);
    }];
}

#pragma mark - 懒加载

- (UIImageView *)iconImageView
{
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.layer.cornerRadius = kUserIconWidth / 2.0;
        _iconImageView.layer.masksToBounds = YES;
    }
    
    return _iconImageView;
}

- (UILabel *)nameLabel
{
    if (_nameLabel == nil) {
        _nameLabel = [UILabel labelWithText:@"陈翔六点半" textColor:[UIColor blackColor] font:15 textAlignment:NSTextAlignmentCenter];
    }
    
    return _nameLabel;
}

- (UILabel *)subscribeNumberLabel
{
    if (_subscribeNumberLabel == nil) {
        _subscribeNumberLabel = [UILabel labelWithText:@"2.5 万" textColor:[UIColor lightGrayColor] font:12 textAlignment:NSTextAlignmentCenter];
    }
    
    return _subscribeNumberLabel;
}

- (UIButton *)subscribeButton
{
    if (_subscribeButton == nil) {
        _subscribeButton = [UIButton buttonWithTitle:@"+ 订阅" fontSize:15 titleColor:[UIColor redColor] backgroundImageName:@"tagButtonBG" highlightedBackgroundImageName:@"tagButtonBGClick" target:nil action:nil];
    }
    
    return _subscribeButton;
}

@end
